package com.labichaoka.chaoka.ui.baseinfo.information;

import com.labichaoka.chaoka.base.MyApplication;
import com.labichaoka.chaoka.entity.BaseResponse;
import com.labichaoka.chaoka.entity.CreditCardResponse;
import com.labichaoka.chaoka.entity.IDCardResponse;
import com.labichaoka.chaoka.entity.VerifyInfoListResponse;
import com.labichaoka.chaoka.net.BaseSubscriber;
import com.labichaoka.chaoka.net.DataManager;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by ruan on 2018/8/2.
 */

public class InformationAuthenticationInteractorImpl implements InformationAuthenticationInteractor {
    private DataManager manager = new DataManager(MyApplication.mContext);
    private CompositeSubscription mCompositeSubscription = new CompositeSubscription();

    @Override
    public void getIdName(OnFinishedListener listener) {
        mCompositeSubscription.add(manager.queryIDCard()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<IDCardResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        listener.onGetIdNameFailed();
                    }

                    @Override
                    public void onNext(IDCardResponse response) {
                        super.onNext(response);
                        listener.onGetIdNameSuccessed(response);
                    }
                })



        );
    }

    @Override
    public void behavior(String actionNode) {
        mCompositeSubscription.add(manager.behavior(actionNode)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<BaseResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onNext(BaseResponse response) {
                        super.onNext(response);
                    }
                })
        );
    }

    @Override
    public void getVerifyInfoList(OnFinishedListener listener) {
        mCompositeSubscription.add(manager.getVerifyInfoList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<VerifyInfoListResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        listener.onGetVerifyInfoListFailed();
                    }

                    @Override
                    public void onNext(VerifyInfoListResponse response) {
                        super.onNext(response);
                        listener.onGetVerifyInfoListSucc(response);
                    }
                })



        );
    }

    @Override
    public void creditCardSwitch(OnFinishedListener listener) {
        mCompositeSubscription.add(manager.creditCardSwitch()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<CreditCardResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        listener.onCreditCardFailed();
                    }

                    @Override
                    public void onNext(CreditCardResponse response) {
                        super.onNext(response);
                        listener.onCreditCardSucc(response);
                    }
                })



        );

    }

}
